﻿package com.singlenotion.display.buttons 
{
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	/**
	 * ...
	 * @author Adam Jowett (Single Notion)
	 */
	public class CheckBox extends GenericButton
	{
		private var _checked:Boolean;
		
		public function CheckBox($on:Boolean = true) 
		{
			super($on);
		}
		
		override protected function onReleaseListener($e:MouseEvent):void 
		{
			checked = !checked;
			dispatchEvent(new Event(ButtonEvents.ON_RELEASE, false, true));
		}
		
		override protected function onRollOutListener($e:MouseEvent):void 
		{
			if (!_checked) {
				gotoAndStop("up");
			} else {
				gotoAndStop("checked");
			}
			dispatchEvent(new Event(ButtonEvents.ON_ROLLOUT, false, true));
		}
		
		override protected function onRollOverListener($e:MouseEvent):void
		{
			if (!_checked) gotoAndStop("over");
			dispatchEvent(new Event(ButtonEvents.ON_ROLLOVER, false, true));
		}
		
		public function get checked():Boolean { return _checked; }
		
		public function set checked($val:Boolean):void
		{
			if ($val) gotoAndStop("checked"); else gotoAndStop("up");
			_checked = $val;
		}
	}
}